package chihane.jdaddressselector;

import android.content.Context;

import com.alibaba.fastjson.JSONObject;

import java.io.IOException;
import java.io.InputStream;
import java.util.List;
import java.util.Scanner;

import chihane.jdaddressselector.model.Province;

public class AddressUtil {
    public static List<Province> getData(Context context){
        String s = null;
        List<Province> list = null;
        try {
            InputStream is = context.getAssets().open("address.json");
            Scanner scanner = new Scanner(is, "UTF-8").useDelimiter("\\A");
            if (scanner.hasNext()) {
                s = scanner.next();
            }
            is.close();
            list = JSONObject.parseArray(s, Province.class);

        } catch (IOException e) {
            e.printStackTrace();
        }

        return list;
    }

    public static List<Province> getData1(Context context){
        String s = null;
        List<Province> list = null;
        try {
            InputStream is = context.getAssets().open("adapay.json");
            Scanner scanner = new Scanner(is, "UTF-8").useDelimiter("\\A");
            if (scanner.hasNext()) {
                s = scanner.next();
            }
            is.close();
            list = JSONObject.parseArray(s, Province.class);

        } catch (IOException e) {
            e.printStackTrace();
        }

        return list;
    }

}
